

<template>
  <div class="execution">
    <basic-container>
      <avue-crud ref="crud"
                 :page="page"
                 :data="tableData"
                 :table-loading="tableLoading"
                 :option="tableOption"
                 @on-load="getList"
                 @search-change="searchChange"
                 @refresh-change="refreshChange"
                 @row-update="handleUpdate"
      >
        <template slot="menuLeft">
          <div class="heardBtn">
            <div class="label">清退文件名称 </div>
            <el-input v-model="fileName" size="mini"  clearable class="h-input"></el-input>
            <el-button   type="primary" size="mini" class="btn h-btn" @click="postDumpfunc"  :loading="btnLoading"  >立即获取并上传</el-button>

          </div>
          <slot></slot>
          <br/><br/>
        </template>
        <template slot-scope="scope"
                  slot="menu">
          <el-button type="text"
                     icon="el-icon-check"
                     size="small"
                     plain
                     @click="sendEmail(scope.row)">重发邮件
          </el-button>
        </template>
      </avue-crud>
    </basic-container>


  </div>
</template>

<script>
import {fetchList, sendEmail, postDump} from '@/api/antborrow/loanClearList'
import {tableOption} from '@/const/crud/antborrow/loanClearList'
import {mapGetters} from 'vuex'
export default {
  name: 'locanclearlist',
  components: {
  },
  props: {
    contracts: String,
    default: () => {
      return ''
    }
  },
  data() {
    return {
      btnLoading: false,
      dialogTableVisible: false,
      termContractNo: '',
      tableData: [],
      page: {
      },
      tableLoading: false,
      tableOption: tableOption,
      fileName: ""
    }
  },
  created() {
  },
  mounted: function () {
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    getList(page) {
      this.tableLoading = true
      console.log(this.queryParams);


      let tempData = {};
      if(this.queryParams.tempTime && this.queryParams.tempTime.length == 2) {
        Object.assign(tempData, this.queryParams,{
          startTime: this.queryParams.tempTime[0],
          endTime: this.queryParams.tempTime[1],
          tempTime: []
        })
      } else {
        Object.assign(tempData, this.queryParams)
      }

      fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize,
        contractList: this.contracts
      }, tempData)).then(response => {
        let arr = response.data.data.records;
        console.log(arr);
        this.tableData = response.data.data.records
        this.page.pageSize = response.data.data.pageSize
        this.page.total = response.data.data.total
        this.tableLoading = false
      })
    },

    sendEmail(row) {
      sendEmail({id: row.id}).then(res => {
        if (res.data.code === 0) {
          this.$message.success('发送成功')
          this.getList(this.page)
        }
      })
    },
    postDumpfunc() {
      this.btnLoading = true
      postDump({fileName: this.fileName}).then(res=>{
        if (res.data.code === 0) {
          this.$message.success('操作成功')
          this.btnLoading = false
          this.fileName = ""
          this.getList(this.page)
        }
      }).catch(err => {
        this.btnLoading = false
        this.getList(this.page)
      })

    },


    /**
     **/
    handleUpdate: function (row, index, done) {
      putObj(row).then(data => {
        this.tableData.splice(index, 1, Object.assign({}, row))
        this.$message({
          showClose: true,
          message: '修改成功',
          type: 'success'
        })
        done()
        this.getList(this.page)
      })
    },

    /**
     */
    searchChange(form) {
      this.queryParams = this.filterForm(form)
      this.getList(this.page)
    },
    /**
     */
    refreshChange() {
      this.getList(this.page)
    }
  }
}
</script>

<style lang="scss" scoped>
.heardBtn {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  .label {
    white-space: nowrap;
    font-size: 14px;
    margin-right: 12px;
  }
  .btn {
    margin-left: 10px;
  }
}

::v-deep .el-input--mini input {
  height: 33px!important;
}
::v-deep .h-input .el-input__inner {
  width: 173px;
}
::v-deep .el-range-editor--small.el-input__inner {
  width: 300px!important;
}
.h-btn {
  padding:9px 15px;
}

</style>
